package com.liming.salesman.webapp.wicket.page;

import com.liming.salesman.api.biz.IDistributorBeanService;
import com.liming.salesman.api.persistence.IDistributorBean;
import org.apache.aries.blueprint.annotation.Reference;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.CompoundPropertyModel;

import javax.inject.Inject;
import javax.inject.Named;

/**
 * @类描述：修改分销商
 * @创建人：wangkr
 * @创建时间：2014-03-28 下午10:47
 * @修改人：
 * @修改时间：
 * @修改备注：
 */

public class ModifyDistributor extends Panel {


    @Named
    @Inject
    @Reference(id = "distributorBeanService", serviceInterface = IDistributorBeanService.class)
    private IDistributorBeanService distributorBeanService;

    TextField name;
    TextField mobile;
    TextField address;
    TextField contact;
    TextField zipcode;
    IDistributorBean distributor;

    public ModifyDistributor(String id, IDistributorBean modifyDistributor) {
        super(id);
        distributor = modifyDistributor;

        Form form = new Form<IDistributorBean>("modify_distributor_form", new CompoundPropertyModel<IDistributorBean>(distributor)) {
            @Override
            protected void onSubmit() {
                distributor.setName(name.getValue());
                distributor.setMobile(mobile.getValue());
                distributor.setAddress(address.getValue());
                distributor.setContact(contact.getValue());
                distributor.setZipcode(zipcode.getValue());
                distributorBeanService.addEntity(distributor);
                setResponsePage(ListDistributor.class);
            }
        };
        add(form);


        name = new TextField("name");
        mobile = new TextField("mobile");
        address = new TextField("address");
        contact = new TextField("contact");
        zipcode = new TextField("zipcode");

        form.add(name);
        form.add(mobile);
        form.add(address);
        form.add(contact);
        form.add(zipcode);
    }
}
